package com.ruoyi.web.controller.dongfang;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.question.domain.Article;
import com.ruoyi.question.service.IArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/question/articleApprove")
public class ArticleApproveController extends BaseController {
    private String prefix = "question/article";

    @Autowired
    private IArticleService articleService;

    @RequiresPermissions("question:articleApprove:view")
    @GetMapping()
    public String dfApprove()
    {
        return prefix + "/articleApprove";
    }

    /**
     * 审核通过
     */
    @Log(title = "审核通过", businessType = BusinessType.UPDATE)
    @PostMapping("/pass")
    @ResponseBody
    public AjaxResult pass(HttpServletRequest httpRequest)
    {
        Long id = Long.valueOf(httpRequest.getParameter("id"));
        Article article = articleService.selectArticleById(id);
        article.setApproveStatus(1);
        return AjaxResult.success(articleService.updateArticle(article));
    }
    /**
     * 审核失败
     */
    @Log(title = "审核失败", businessType = BusinessType.UPDATE)
    @PostMapping("/fail")
    @ResponseBody
    public AjaxResult fail(HttpServletRequest httpRequest)
    {
        Long id = Long.valueOf(httpRequest.getParameter("id"));
        Article article = articleService.selectArticleById(id);
        article.setApproveStatus(2);
        return AjaxResult.success(articleService.updateArticle(article));
    }

    /**
     * 查看问题
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") Long id, ModelMap mmap)
    {
        Article article = articleService.selectArticleById(id);
        mmap.put("article", article);
        return prefix + "/view";
    }
}
